//定时任务
import { scheduleJob,RecurrenceRule } from 'node-schedule'
import { CORN_MAIN1,CORN_MAIN2 } from './cornfunc'

const rules = {}
rules.everyH = '0 0 * * * *'
rules.everyMin = '0 * * * * *'
rules.everyH2 = new RecurrenceRule()
rules.everyH2.hour = [7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]
rules.everyH2.minute = [0,30]
rules.everyH2.second = 0
rules.everyH4 = new RecurrenceRule()
rules.everyH4.hour = [7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]
rules.everyH4.minute = [0,15,30,45]
rules.everyH4.second = 0
rules.everyD3 = new RecurrenceRule()
rules.everyD3.hour = [8,12,18]
rules.everyD3.minute = 0
rules.everyD3.second = 0

export const CORN_ING1 = () => {
  const allList = [
    {city:'沈北新区',username:'非鱼鱼鱼鱼鱼',mail:'992721440@qq.com',rule:'everyD3'},
    {city:'元氏',username:'菜菜',mail:'821783496@qq.com',rule:'everyD3'},
    {city:'深圳',username:'鬼鬼',mail:'m133029402511@163.com',rule:'everyD3'},
    {city:'津南',username:'朱小姐',mail:'1980625192@qq.com',rule:'everyH'},
    {city:'阳原',username:'饭饭',mail:'1317001011@qq.com',rule:'everyH'}
  ]
  for(const item of allList){
    const { city,username,mail,rule } = item
    // CORN_MAIN1(city,username,mail)
    scheduleJob(rules[rule],CORN_MAIN1.bind(null,city,username,mail))
  }
}

export const CORN_ING2 = () => {
  const allList = [
    {fromname:'饭女士',username:'李先生',mail:'2210333097@qq.com',rule:'everyH'},
    {fromname:'饭女士',username:'陆女士',mail:'599657057@qq.com',rule:'everyH'},
  ]
  for(const item of allList){
    const { username,mail,fromname,rule } = item
    // CORN_MAIN2(fromname,username,mail)
    scheduleJob(rules[rule],CORN_MAIN2.bind(null,fromname,username,mail))
  }
}